<template>
	<view>
		<ad-rewarded-video ref="adRewardedVideo" adpid="1501138598" :preload="false" :disabled="true"
			v-slot:default="{adVideoLoading, adVideoError}" @load="onadload" @close="onadclose" @error="onaderror">
			<view class="ad-error" v-if="adVideoError">{{adVideoError}}</view>
		</ad-rewarded-video>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				adVideoLoading: false,
				adVideoError: ''
			}
		},
		methods: {
			onadload(e) {
				this.adVideoLoading = false;
			},
			onadclose(e) {
				const detail = e.detail
				// 用户点击了【关闭广告】按钮
				if (detail && detail.isEnded) {
					// 正常播放结束
					this.$http.post('client/reward/setUseableNum', {}, {
						token: true
					}).then(res => {
						uni.showToast({
							icon: "none",
							title: res.data.msg
						})
					});
				} else {
					//播放中途退出
					uni.showToast({
						icon: "none",
						title: '中途退出，获取免费机会失败'
					})
				}
			},
			onaderror(e) {
				// 广告加载失败
				this.adVideoLoading = false;
				this.adVideoError = e;
			}
		}
	}
</script>

<style>

</style>